

import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.*;
import org.eclipse.swt.layout.*;
import org.eclipse.swt.widgets.*;

import java.io.*;
import java.text.*;
import java.util.*;

import swing2swt.layout.BoxLayout;
import swing2swt.layout.BorderLayout;

import org.eclipse.swt.custom.ScrolledComposite;
import org.eclipse.swt.custom.SashForm;
import org.eclipse.swt.custom.TableCursor;




public class MyShop {
	private static Table table;
	private static Text text;

	public static void main(String[] args) {
			
		
		final Display display = new Display();
		final Shell shell = new Shell(display);
		shell.setSize(592, 416);
		
		shell.setText("hello world.");
		shell.setLayout(new FormLayout());
		
		
		ToolBar toolBar = new ToolBar(shell, SWT.FLAT | SWT.RIGHT);
		FormData fd_toolBar = new FormData();
		fd_toolBar.right = new FormAttachment(0, 569);
		fd_toolBar.top = new FormAttachment(0);
		fd_toolBar.left = new FormAttachment(0);
		toolBar.setLayoutData(fd_toolBar);
		
		ToolItem tltmNewItem = new ToolItem(toolBar, SWT.NONE);
		tltmNewItem.setText("New Item");
		
		ToolItem tltmNewItem_1 = new ToolItem(toolBar, SWT.NONE);
		tltmNewItem_1.setText("New Item2");
		
		TabFolder tabFolder = new TabFolder(shell, SWT.NONE);
		FormData fd_tabFolder = new FormData();
		fd_tabFolder.top = new FormAttachment(0, 83);
		fd_tabFolder.left = new FormAttachment(0);
		fd_tabFolder.bottom = new FormAttachment(100, -8);
		fd_tabFolder.right = new FormAttachment(100, -46);
		tabFolder.setLayoutData(fd_tabFolder);
		
		TabItem tbtmTable = new TabItem(tabFolder, SWT.NONE);
		tbtmTable.setText("Table");
		
		/// Tables
		table = new Table(tabFolder, SWT.BORDER | SWT.FULL_SELECTION);
		tbtmTable.setControl(table);
		table.setHeaderVisible(true);
		table.setLinesVisible(true);
		
		
		
		TableColumn tblclmnId = new TableColumn(table, SWT.NONE);
		tblclmnId.setToolTipText("id column");
		tblclmnId.setWidth(100);
		tblclmnId.setText("id");
		
				TableColumn tblclmnName = new TableColumn(table,  SWT.BORDER  | SWT.MULTI | SWT.FULL_SELECTION);
				tblclmnName.setWidth(100);
				tblclmnName.setText("Name");
				tblclmnName.setMoveable(true);
				tblclmnId.setMoveable(true);
				
				
				//Table Data
				TableItem item = new TableItem(table, SWT.NULL);
				item.setText(0,"a");
				item.setText(1, "1");
				TableItem item2 = new TableItem(table, SWT.NULL);
				item2.setText(0,"b");
				item2.setText(1, "2");
				TableItem item3 = new TableItem(table, SWT.NULL);
				item3.setText(0,"c");
				item3.setText(1, "3");
				
			

				
			
			
				
				
		TabItem tabItem = new TabItem(tabFolder, SWT.NONE);
		tabItem.setText("New Item");
		
		SashForm sashForm = new SashForm(tabFolder, SWT.BORDER | SWT.SMOOTH);
		tabItem.setControl(sashForm);
		
		Button btnRadioButton_1 = new Button(sashForm, SWT.RADIO);
		btnRadioButton_1.setText("Radio Button");
		
		Button btnCheckButton = new Button(sashForm, SWT.CHECK);
		btnCheckButton.setText("Check Button");
		sashForm.setWeights(new int[] {1, 1});
			

		TableCursor tableCursor = new TableCursor(table, SWT.NONE);	
			
			
		
		TabItem tabItem_2 = new TabItem(tabFolder, SWT.NONE);
		tabItem_2.setText("New Item");
		
		Composite composite_1 = new Composite(tabFolder, SWT.NONE);
		tabItem_2.setControl(composite_1);
		
		Button btnRadioButton = new Button(composite_1, SWT.RADIO);
		btnRadioButton.setBounds(45, 99, 90, 16);
		btnRadioButton.setText("Radio Button");
		
		TabItem tabItem_3 = new TabItem(tabFolder, SWT.NONE);
		tabItem_3.setText("New Item");
		
		TabItem tabItem_4 = new TabItem(tabFolder, SWT.NONE);
		tabItem_4.setText("New Item");
		
		Tree tree = new Tree(tabFolder, SWT.BORDER);
		tabItem_4.setControl(tree);
		
		text = new Text(shell, SWT.BORDER);
		FormData fd_text = new FormData();
		fd_text.top = new FormAttachment(toolBar, 6);
		fd_text.left = new FormAttachment(toolBar, 0, SWT.LEFT);
		text.setLayoutData(fd_text);
		
		Button btnNewButton = new Button(shell, SWT.NONE);
		FormData fd_btnNewButton = new FormData();
		fd_btnNewButton.bottom = new FormAttachment(text, 0, SWT.BOTTOM);
		fd_btnNewButton.left = new FormAttachment(text, 8);
		btnNewButton.setLayoutData(fd_btnNewButton);
		btnNewButton.setText("Search");
		
		btnNewButton.addSelectionListener(new SelectionAdapter() {
		      public void widgetSelected(SelectionEvent e) {
		        TableItem[] tia = table.getItems();

		        for (int i = 0; i < tia.length; i++) {
		          if (tia[i].getText(1).equals(text.getText())) {
		            tia[i].setBackground(new Color(display, 127, 178, 127));
		          }

		        }
		      }
		});
		
		Button addBtn = new Button(shell, SWT.NONE);
		FormData fd_addBtn_1 = new FormData();
		fd_addBtn_1.top = new FormAttachment(btnNewButton, 0, SWT.TOP);
		fd_addBtn_1.left = new FormAttachment(btnNewButton, 6);
		addBtn.setLayoutData(fd_addBtn_1);
		addBtn.setText("add");
		
				
		Button btnNewButton_1 = new Button(shell, SWT.NONE);
		FormData fd_btnNewButton_1 = new FormData();
		fd_btnNewButton_1.bottom = new FormAttachment(text, 0, SWT.BOTTOM);
		fd_btnNewButton_1.left = new FormAttachment(addBtn, 6);
		btnNewButton_1.setLayoutData(fd_btnNewButton_1);
		btnNewButton_1.setText("Open table in window");
		
		final MainLayout ml = new MainLayout();
		
		
		btnNewButton_1.addSelectionListener(new SelectionAdapter() {
			public void widgetSelected(SelectionEvent e){
				ml.MainLayout(shell);
			}
		});
		
		addBtn.addSelectionListener(new SelectionAdapter() {
			public void widgetSelected(SelectionEvent e){
				TableItem item = new TableItem(table, SWT.NULL);
				item.setText(1,text.getText());
			}
		});
		
		
		
		shell.setTabList(new Control[]{toolBar});
				
		
		shell.open();
		while (! shell.isDisposed()) {
			if (! display.readAndDispatch()) display.sleep();
		}
		
		
		
		/*Dress myDress = new Dress();
		
		myDress.setName("Some black dress with white sticks.!");
		//Create a panel and add components to it.

		
		
		System.out.println("System is Run");
		System.out.println("Name value is: "+ myDress.getName());*/

		
	}
}
